package com.itheima_8;

import java.io.*;
import java.net.Socket;
import java.util.Date;

import static jdk.nashorn.internal.objects.Global.println;

public class ServerDemo implements Runnable{
    private File desetPath=new File("E:\\上传文件");
    private Socket socket;
    public ServerDemo(Socket socket) {
        this.socket=socket;
    }
        @Override
    public void run() {
            try {
                OutputStream os = socket.getOutputStream();
                PrintWriter pw=new PrintWriter(os,true);
                pw.println("欢迎光临！请上传文件");
                File file=new File(desetPath,new Date().getTime()+"_update.txt");
                InputStream is=socket.getInputStream();
                BufferedReader br =new BufferedReader(new InputStreamReader(is));
                PrintWriter p=new PrintWriter(new FileOutputStream(file),true);
                String s;
                while ((s=br.readLine())!=null){
                    if(s.contains("操")){
                        s=s.replace("操","**");
                    }
                    p.println(s);
                }
                p.close();
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
}
